package org.nbict.iot.trash.mogo;

import org.apache.commons.lang.Validate;
import org.apache.storm.task.OutputCollector;
import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.base.BaseRichBolt;

import java.util.Map;

/**
 * Created by songseven on 18/6/20.
 */
@Deprecated
public abstract class AbstractMongoBolt extends BaseRichBolt {

    private String url;
    private String username;
    private String password;
    private String adminname;
    private String database;
    private String collectionName;
    protected OutputCollector collector;
    protected MongoDBClient mongoClient;

    public AbstractMongoBolt(String url, String username, String password, String adminname, String database, String collectionName) {
        Validate.notEmpty(url, "url can not be blank or null");
        Validate.notEmpty(collectionName, "collectionName can not be blank or null");
        this.url = url;
        this.collectionName = collectionName;
        this.username = username;
        this.password = password;
        this.adminname = adminname;
        this.database = database;
    }

    public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
        this.collector = collector;
        this.mongoClient = new MongoDBClient(this.url, this.username, this.adminname, this.password, this.database, this.collectionName);
    }

    public void cleanup() {
        this.mongoClient.close();
    }
}
